﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BaseSet.Data;
using BaseSet.Logic;
using BaseSet.Entity;
using BaseSet.Framework;
using BaseSet.Entity.Common;
using BaseSet.Entity.Common.Text;
using BaseSet;
using System.Data;
using System.Text;

namespace WebSite.Ajax
{
    public partial class FindPassword : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string email = Request.QueryString["email"] + "";
            string captcode = Request.QueryString["captcode"] + "";
 
            //判断验证码是否正确
            string code = Session["code"] + "";
            if (captcode != code)
            {
                Response.Write("2");
                return;
            }
            else
            {
                //判断邮箱是否存在
                UsersHelper uhelper = new UsersHelper();
                Criteria c = new Criteria();
                c.Add(CriteriaType.Equals, "Email", email);
                c.Add(CriteriaType.Equals, "Flag", 0);
                c.Add(CriteriaType.Equals, "RoleType", 1);

                List<Users> ulist = uhelper.QueryUsersBySearch(c, null);
                if (ulist.Count > 0)
                {
                    Users uinfo = ulist[0];
                    string password = uinfo.Password;//加密的密码
                    string nickname = uinfo.NickName;
                    string yuanpassword = Encrypt.Decode(password);//解密后的密码
                    //发送邮件
                    string title = "友赢网找回密码";
                    StringBuilder sbContent = new StringBuilder();
                    sbContent.Append("<h3>亲爱的友赢网用户 " + nickname + "：</h3>");
                    sbContent.Append("您好，<br/>");
                    sbContent.Append("您在友赢网的登录密码为： <font color= 'red'><u><b>" + yuanpassword);
                    sbContent.Append("</b></u></font>");
                    bool ifsend= SendEmail.SendEmailByJmail(email, nickname, title, sbContent.ToString());
                    if (ifsend)
                    {
                        Response.Write("1");
                        return;
                    }
                    else
                    {
                        Response.Write("-1");
                        return;
                    }
                }
                else//该邮箱系统中不存在
                {
                    Response.Write("3");
                    return;
                }
            }
        }
    }
}